package chain.example.delivery.chain;


import chain.example.delivery.decorate.NoneInfo;
import chain.example.delivery.decorate.StateInfo;

import java.util.ArrayList;
import java.util.List;

public class DeliveryChainDefaultImpl implements DeliveryChain {
    int pos = 0;
    private static List<Delivery> chainItems = new ArrayList<>();

    static  {
        chainItems.add(new NotPayChain());
        chainItems.add(new PayedChain());
        chainItems.add(new ShopDeliveryChain());
        chainItems.add(new RealDeliveryChain());
    }


    public StateInfo doChain(int state) {
        if (pos == chainItems.size()) {
            return new NoneInfo();
        }
        Delivery delivery = chainItems.get(pos);
        pos++;
        StateInfo stateInfo = delivery.doDelivery(state, this);
        pos = 0;
        return stateInfo;
    }

}
